package org.opens.javaskill;

import com.google.common.collect.Lists;
import org.apache.commons.collections4.list.UnmodifiableList;
import org.junit.Test;

import java.util.*;
import java.util.stream.Collectors;

public class Arr2List {

    /**
     * 输出:
     *      1
     *      3
     * 总结:
     *      int[]不能用Arrays.asList方法进行转换, Arrays.asList的参数必须是对象.
     */
    @Test
    public void test1() {
        int[] arr1 = new int[]{1, 2, 3};
        Integer[] arr2 = new Integer[]{1, 2, 3};
        System.out.println(Arrays.asList(arr1).size());
        System.out.println(Arrays.asList(arr2).size());
    }

    /**
     * 输出:
     *      报错java.lang.NullPointerException
     * 总结:
     *      Arrays.asList不能转换null
     */
    @Test
    public void test2() {
        Integer[] arr1 = null;
        System.out.println(Arrays.asList(arr1).size());
    }

    /**
     * 简介:
     *      如果List为空(size = 0), 使用get(0)会报错.
     * 报错内容:
     *      java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
     */
    @Test
    public void test3() {
        List<Integer> arr = new ArrayList<>();
        System.out.println(arr.get(0));
    }

    /**
     * 简介:
     *      使用java转义正则内置符号然后进行切割字符串.
     * 输出:
     *      asd
     *      123
     *      asd
     */
    @Test
    public void test4() {
        String str = "asd$123$asd";
        for (String s : str.split("\\$")) {
            System.out.println(s);
        }
    }

    /**
     * 创建长度为0的map并不会报错
     */
    @Test
    public void test5() {
        Map<String, String> map = new HashMap<>(0);
        System.out.println(map.get("1"));
        map.put("sds", "sdasd");
        System.out.println(map.toString());
    }

    @Test
    public void testArrOutOfBound() {
        ArrayList<Object> list = Lists.newArrayList();
        System.out.println(list.get(0));
    }

    @Test
    public void testArrLength() {
        String[][] arr = new String[30][];
        arr[1] = new String[]{"1", "1", "1", "1", "1", "1", "1"};
        arr[2] = new String[]{"2", "2", "2", "2", "2", "2", "2"};

        List<String[]> list = new ArrayList<>();
        list.add(new String[]{"1", "1", "1", "1", "1", "1", "1"});
        list.add(new String[]{"2", "2", "2", "2", "2", "2", "2"});
        System.out.println(list);
        System.out.println(list.toArray());
    }

    @Test
    public void longAdd() {
        long i = 1L;
        int y = (int) (i + i);
        System.out.println(y);
    }

    @Test
    public void test111() {
        List<String> list = Lists.newArrayList("1", "2", "3");
        System.out.println(list.contains("11"));
    }

    @Test
    public void test123() {
        byte[] arr = new byte[]{1, 2, 3};
        System.out.println(arr.length);
    }

    @Test
    public void test1111() {
        List<Integer> ids = Lists.newArrayList(1, 2, 3);
        UnmodifiableList<Integer> list = new UnmodifiableList<>(ids);

        List<Integer> collect = new ArrayList<>(list);
        collect.remove(1);
        System.out.println(collect);
    }

}
